package fr.aura.launcher.client;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;

import org.apache.log4j.Logger;

public class LNCSrvMsgHeader {
	/**
	 * 
	 */

	
	private short iVersion;
	private int lSize;
	private static int byteSize = 2+4;
	static Logger logger = Logger.getLogger(LNCSrvMsg.class.getName());
	
	public int getByteSize() {
		return byteSize;
	}
	
	public short getiVersion() {
		return iVersion;
	}
	public void setiVersion(short iVersion) {
		this.iVersion = iVersion;
	}
	public int getlSize() {
		return lSize;
	}
	public void setlSize(int lSize) {
		this.lSize = lSize;
	}
	
	public byte[] toByteArray() {
		//default buffer endian order is BIG_ENDIAN, Launcher send and receive little endian only
		ByteBuffer myBuffer = ByteBuffer.allocate(byteSize);
		myBuffer.order(ByteOrder.LITTLE_ENDIAN);
		myBuffer.putShort(this.iVersion).putInt(this.lSize);
		
		return myBuffer.array();
	}
	
	public void fromByteArray(byte[] byteArray) {
		ByteBuffer myBuffer = ByteBuffer.wrap(byteArray);
		myBuffer.order(ByteOrder.LITTLE_ENDIAN);
		this.iVersion = myBuffer.getShort();
		this.lSize = myBuffer.getInt();
	}

	public void fromByteArray(ByteBuffer myBuffer) {
		this.iVersion = myBuffer.getShort();
		this.lSize = myBuffer.getInt();
	}
}
